//
//  UIScrollView+HHRefresh.swift
//  BCScrollViewKit
//
//  Created by chun.chen on 2021/8/26.
//  UIScrollView+下拉刷新

extension UIScrollView {
    //MARK: - property
    public var hh_header: MJRefreshHeader? {
        return self.mj_header
    }
    public var hh_footer: MJRefreshFooter? {
        return self.mj_footer
    }
    
    /// 添加下拉刷新
    /// - Parameter closure: closure description
    public func addPullToRefreshWithAction(_ closure: @escaping (UIScrollView) -> (Void)) {
       
       let header =  HHRefreshHeader { [weak self] in
            guard let `self` = self else {
                return
            }
            closure(self)
        }.autoChangeTransparency(true)
        .link(to: self)
        
        header.lastUpdatedTimeLabel?.isHidden = true
        header.stateLabel?.isHidden = true
        
    }
    
    /// 添加上拉加载更多
    /// - Parameter closure: closure description
    public func addInfiniteScrollingWithAction(_ closure: @escaping (UIScrollView) -> (Void)) {
        
        let _ =  MJRefreshAutoNormalFooter { [weak self] in
             guard let `self` = self else {
                 return
             }
             closure(self)
         }.autoChangeTransparency(true)
         .link(to: self)
     }
}
